<template>
  <div class="quality-wrapper">
    <ekt-base-icon title="质控留痕" @handle-click="toggleModal"></ekt-base-icon>

    <ekt-quality-form
      :text="text"
      :content="content"
      :visible.sync="visible"
      @handle-close="toggleModal"
      @handle-submit="submitForm"
    ></ekt-quality-form>
  </div>
</template>

<script>
import cookie from "../../common/cookie";
import { postSubmitControlUrl } from "../../common/ajax";
export default {
  props: {
    content: String,
    text: String,
    dateTips: String,
  },
  data() {
    return {
      visible: false,
      isLoading: false,
    };
  },
  methods: {
    submitForm(form) {
      if (this.isLoading) return;
      jQuery.ajax({
        type: 'POST',
        url: postSubmitControlUrl,
        dataType: 'json',
        contentType: 'application/json;charset=UTF-8',
        data: JSON.stringify({
          uname: cookie.get("nickname"),
          comments: form.comments,
          step_name: form.uname,
          origin_time: this.dateTips, // 查询时间
          origin_html: this.text, // 查询界面
          origin_des: this.content, // 查询内容
        }),
        success: function(res){
          if(res.success){
            this.$Message({
              showClose: true,
              message: '保存成功',
              type: 'success'
            });
          }else{
            throwErrorTips('',res.msg)
          }
        }.bind(this)
      })
    },
    toggleModal() {
      this.visible = !this.visible;
    },
  },
};
</script>

<style lang="less" scoped>
.quality-wrapper {
  display: inline-block;
  vertical-align: middle;
}
</style>